﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zocono.WCS.Domain.PlcBytesObject
{
    public class QTScMessageWcsActionBO : BytesObjectBase
    {

        /// <summary>
        /// 下发的任务号码
        /// </summary>
        public int ExecutedJobNum { get; set; }
        /// <summary>
        /// 双叉机型适用1：使用货叉1；2：使用货叉2；3：同时使用双货叉；
        /// </summary>
        public short ForkControl { get; set; }

        /// <summary>
        /// 下发的源排
        /// </summary>
        public short FromRow { get; set; }

        /// <summary>
        /// 下发的源列
        /// </summary>
        public short FromCol { get; set; }

        /// <summary>
        /// 下发的源层
        /// </summary>
        public int FromLayer { get; set; }

        /// <summary>
        /// 下发的源纵深
        /// </summary>
        public short FromDepth { get; set; }

        /// <summary>
        /// 下发的目标排
        /// </summary>
        public short ToRow { get; set; }

        /// <summary>
        /// 下发的目标列
        /// </summary>
        public short ToCol { get; set; }

        /// <summary>
        /// 下发的目标层
        /// </summary>
        public short ToLayer { get; set; }

        /// <summary>
        /// 下发的目标纵深
        /// </summary>
        public short ToDepth { get; set; }

        /// <summary>
        /// 1：取放（去源位置取货，目标位置放货）；2：取货（去源位置取货）；
        /// 3：放货（去目标位置放货）；4：行走（移动到源位置）；5：急停；
        /// 6：复位；7：任务删除； 8：灭火（去源位置灭火）；
        /// 9：取放+灭火（去源位置取货，目标位置放货，取货开始就开始灭火）；
        /// 10：取放+灭火（去源位置取货，目标位置放货，取货完成后开始灭火）；
        /// </summary>
        public short CommandMode { get; set; }
        /// <summary>
        /// 1：正常流程；2：消防流程；3：异形货物；
        /// </summary>
        public short SpecialTaskFlag { get; set; }
        /// <summary>
        /// 适用于双货叉1：屏蔽货叉1（货叉1故障时，屏蔽货叉1，使用货叉2执行任务）；2：屏蔽货叉2（货叉2故障时，屏蔽货叉2，使用货叉1执行任务）；
        /// </summary>
        public short ForkShield { get; set; }
        /// <summary>
        /// 心跳
        /// </summary>
        public short HeartBeat { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public short YuLiu1 { get; set; }

        public short YuLiu2 { get; set; }
        /// <summary>
        /// 1：任务下发完成，启动下发的任务（PLC读取后改为0）  WCS确认任务完成改为2
        /// </summary>
        public short CompletionFlag { get; set; }


        public override void Serialize(long plcConnectionID, long plcReadDbID, int bytesIndex, int bytesLength, int objectIndex, int objectLength, string objectType, string ScEquipmentCode, byte[] bytes)
        {
            PlcConnectionID = plcConnectionID;
            PlcReadDbID = plcReadDbID;
            BytesIndex = bytesIndex;
            BytesLength = bytesLength;
            ObjectIndex = objectIndex;
            ObjectLength = objectLength;
            /// <summary>
            /// 约定：
            /// 1、设备状态报文以State结尾；
            /// 2、Plc的动作报文以PlcAction结尾；
            /// 3、Wcs的动作报文以WcsAction结尾；
            /// 4、平面PLC报文统一PlcState名称
            /// （后续有其他的再约定）
            /// </summary>
            ObjectType = objectType;
            EquipmentCode = ScEquipmentCode;

            ExecutedJobNum = HelperByte.GetDIntAt(bytes, 0);

            ForkControl = HelperByte.GetIntAt(bytes, 4);

            FromRow = HelperByte.GetIntAt(bytes, 6);

            FromCol = HelperByte.GetIntAt(bytes, 8);

            FromLayer = HelperByte.GetIntAt(bytes, 10);

            FromDepth = HelperByte.GetIntAt(bytes, 12);

            ToRow = HelperByte.GetIntAt(bytes, 14);

            ToCol = HelperByte.GetIntAt(bytes, 16);

            ToLayer = HelperByte.GetIntAt(bytes, 18);

            ToDepth = HelperByte.GetIntAt(bytes, 20);

            CommandMode = HelperByte.GetIntAt(bytes, 22);

            SpecialTaskFlag = HelperByte.GetIntAt(bytes, 24);

            ForkShield = HelperByte.GetIntAt(bytes, 26);

            HeartBeat = HelperByte.GetIntAt(bytes, 28);

            YuLiu1 = HelperByte.GetIntAt(bytes, 30);

            YuLiu2 = HelperByte.GetIntAt(bytes, 32);

            CompletionFlag = HelperByte.GetIntAt(bytes, 34);
        }

    }
}
